package com.ssm.netty.splitpacket;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MyMessageEncoder extends MessageToByteEncoder<MyMessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MyMessageProtocol myMessageProtocol, ByteBuf byteBuf) throws Exception {
        System.out.println("MyMessageEncoder encode 方法被调用了");

        byteBuf.writeInt(myMessageProtocol.getLen());
        byteBuf.writeBytes(myMessageProtocol.getContent());
    }
}
